package com.kirk.cts.core.utils;

import com.google.gson.Gson;
import org.apache.commons.lang.StringUtils;

/**
 * <p> JsonUtils.java </p>
 *
 * @version 1.0.0
 * @Author kirkliu
 * @Date 2020-08-31 22:45
 * @Description JsonUtils工具类
 */
public class JsonUtils {
    private static Gson gson = new Gson();

    /**
     * 格式化任务信息为json格式字符串
     */
    public static String formatObjectToJsonString(Object obj) {
        Gson gson = new Gson();
        String json = gson.toJson(obj);
        if (StringUtils.isNotBlank(json)) {
            return json;
        }
        return "";
    }

    /**
     * 将JSON字符串转换为指定对象
     */
    public static Object formatStringToObject(String jsonString, Class<?> beanClass) {
        Gson gson = new Gson();
        return gson.fromJson(jsonString, beanClass);
    }
}
